//
//  ICGtasksModel.m
//  ICome
//
//  Created by zhangrongwu on 16/6/6.
//  Copyright © 2016年 iCom. All rights reserved.
//

#import "ICGtasksModel.h"
#import "NSDictionary+JSONExtemsion.h"
#import "ICHeaderFile.h"

@implementation ICGtasksModel
- (instancetype)initWithDict:(NSDictionary *)dict {
    if (self = [super init]) {
        if ([dict isKindOfClass:[NSDictionary class]]) {
            [self setValuesForKeysWithDictionary:dict];
            NSDictionary *info = [NSDictionary dictionaryWithJsonString:self.txt];
            self.title   = info[@"title"];
            self.summary = info[@"summary"];
            self.confirmurl = info[@"confirmurl"];
            self.rejecturl  = info[@"rejecturl"];
            self.openurl    = info[@"openurl"];
        }
    }
    return self;
}

- (void)setValue:(id)value forUndefinedKey:(NSString *)key {
    if ([key isEqualToString:@"id"]) {
        self.msgId = value;
    }
    if ([key isEqualToString:@"key"]) {
        self.lastTitle = value;
    }
    
    if ([key isEqualToString:@"lnk"]) {
        self.appUrl = value;
    }
    
    if ([key isEqualToString:@"to"]) {
        self.msgto = value;
    }
    
}

-(NSString *)_createDate {
    NSDate *confromTimesp = [ICGtasksModel dateFromLongLong:self.st];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
    return [dateFormatter stringFromDate:confromTimesp];
}

+(NSDate*)dateFromLongLong:(long long)msSince1970 {
    return [NSDate dateWithTimeIntervalSince1970:msSince1970 / 1000];
}

- (NSString *)appendUserInfoforJSURL:(NSString *)URL msgId:(NSString *)msgId{
    NSString *newUrl = @"";
    NSURL *url = [NSURL URLWithString:URL];
    if (![ICTools stringEmpty:url.query]) {
        newUrl = [NSString stringWithFormat:@"%@&ticket=%@&msgid=%@", URL,[ICTools getJSTicket],msgId];
    } else {
        newUrl = [NSString stringWithFormat:@"%@?ticket=%@&msgid=%@", URL,[ICTools getJSTicket],msgId];
    }
    return newUrl;
}

@end
